package com.briup.day27;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test_List {
    public static void main(String[] args) throws Exception {
        List<Integer> list = new ArrayList<>();
        //利用反射机制去除泛型机制 先获取字节码对象
        //反射在运行时操作，所以不受编译时的限制
        Class<? extends List> clazz = list.getClass();
        Method m1 = clazz.getDeclaredMethod("add", Object.class);
    m1.setAccessible(true);
    m1.invoke(list, 1);
    m1.invoke(list, "hello");
    m1.invoke(list, 2.12);
Iterator<Integer> iterator = list.iterator();
while(iterator.hasNext()){
    System.out.println(iterator.next()+"遍历集合元素");
}
    }
}
